//
//  SearchTtitleView.swift
//  WalkNovel
//
//  Created by Kevin on 2023/7/6.
//

import UIKit

class SearchTtitleView: UIView {
    
    lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .bold, size: 12)
        label.textColor = .black
        return label
    }()
    
    lazy var deleteBtn: UIButton = {
        let btn = UIButton(type: .custom)
        btn.setImage(UIImage(named: "setting_delete_all"), for: .normal)
        btn.rx.tap.bind { [weak self] in
            self?.deleteClosure?()
        }.disposed(by: rx.disposeBag)
        btn.isHidden = true
        return btn
    }()
        
    var deleteClosure: ReturnClosure?
            
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(titleLabel)
        addSubview(deleteBtn)
        titleLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(12)
        }
        deleteBtn.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalTo(-26)
            make.height.width.equalTo(16)
        }
    }

    func setTitleType(_ type: Int) {
        deleteBtn.isHidden = true
        switch type {
        case 0:
            titleLabel.text = "流行"
        case 1:
            titleLabel.text = "搜尋紀錄”"
            deleteBtn.isHidden = false
        default: break
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
